using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PentaBiz.Collections.DataCache;

namespace PentaBiz.Testing.Collections.DataCache
{
    [TestClass]
    public class UnitTestSequentialDataCacheExtensions
    {
        [TestMethod]
        [TestCategory("SequentialDataCacheExtensions")]
        public void TestToSequentialDataCache()
        {
            var data = CreateData();

            //
            var c = data.ToSequentialDataCache();


            Assert.AreEqual(1000, c.Count);

            c.Close();

        }

        [TestMethod]
        [TestCategory("SequentialDataCacheExtensions")]
        public void TestToSequentialDataCacheUsing()
        {
            var data = CreateData();

            string path;
            //
            using (var c = data.ToSequentialDataCache())
            {
                Assert.AreEqual(1000, c.Count);
                path = c.Path;
            }

            Assert.IsFalse(File.Exists(path));




        }


        private static Data[] CreateData()
        {
            //create array
            var datas = new Data[1000];
            for (int i = 0; i < datas.Length; i++)
            {
                var data = new Data()
                               {
                                   Index = i,
                                   TwoDimensionalArray = new double[3, 1000].InitializeArray(),
                               };
                datas.SetValue(data, i);
            }
            return datas;
        }


        [Serializable]
        class Data
        {
            public int Index { get; set; }
            public double[,] TwoDimensionalArray { get; set; }
        }
    }
}